package com.igbeok.miscellaneous.concurrency.thij;

public class Chef extends Thread {
	private Restaurant restaurant;
	private WaitPerson waitPerson;

	public Chef(Restaurant restaurant, WaitPerson waitPerson) {
		this.restaurant = restaurant;
		this.waitPerson = waitPerson;
	}

	public void run() {
		while (true) {
			if (restaurant.order == null) {
				restaurant.order = new Order();
				System.out.println(this + ": Order 已经准备好了, 来拿吧!");
				synchronized (waitPerson) {
					System.out.println(this + ": 我准备通知 WaitPerson!");
					waitPerson.notify();
				}
			}
			try {
				System.out.println(this + ": 我要小睡一会");
				sleep(3000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
		}
	}
}
